Home

Row

Tweets Today

71

Tweeters Today

37

#rstats Likes

440091

#rstats Tweets

45624

Row

Tweet volume

Tweets by Hour of Day

Row

💗 Most Liked Tweet Today

🎉 Most Recent

Rankings

Row

Top Tweeters

User Engagement/Tweet
@v_matzek 2453.0
@kaymwilliamson 1864.0
@TheToadLady 1602.5
@kiramhoffman 1138.0
@adastephenson 1086.0
@hadleywickham 952.5
@drhammed 892.0
@LuukvanderMeer 778.0
@kearneymw 599.4
@Pamela_Moriarty 484.0

Where Engagement is RT * 2 + Favourite

Network of top tweeters

Relationships in the graph describe replies and quote retweets from the top tweeters

Row

Top Hashtags

Hashtag Count
#DataScience 17280
#Python 15500
#IoT 14222
#MachineLearning 12918
#AI 12221
#BigData 11918
#Serverless 11740
#Analytics 11654
#IIoT 11209
#Linux 10391

Excluding #rstats and similar variations

Top Words

Word Count
datascience 21024
python 17899
100daysofcode 15145
machinelearning 14536
bigdata 12956
javascript 12619
serverless 12357
analytics 12354
iiot 11294
programming 11258

Data

Tweets in the current week

---
title: "#rstats Twitter Explorer"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source_code: embed
    theme:
      version: 4
      bootswatch: yeti
    css: styles/main.css
---

```{r load_package, include=FALSE}
devtools::load_all()
```

```{r setup, include=FALSE, cache=TRUE}
library(flexdashboard)
library(rtweet)
library(dplyr)
library(stringr)
library(tidytext)
library(lubridate)
library(echarts4r)
library(DT)

rstats_tweets <- read_twitter_csv("data/rstats_tweets.csv")

count_timeseries <- rstats_tweets %>%
  ts_data(by = "hours")

tweets_week <- rstats_tweets %>%
  filter(as_datetime(created_at) %within% interval(floor_date(today(), "week"), today()))

tweets_today <- rstats_tweets %>%
  filter(created_at == today())

by_hour <- rstats_tweets %>%
  group_by(hour = hour(created_at)) %>%
  summarise(count = n()) %>%
  ungroup()

number_of_unique_tweets <- get_unique_value(rstats_tweets, text)

number_of_unique_tweets_today <-
  get_unique_value(tweets_today, text)

number_of_tweeters_today <- get_unique_value(tweets_today, user_id)

number_of_likes <- rstats_tweets %>%
  pull(favorite_count) %>%
  sum()

top_tweeters <- rstats_tweets %>%
  group_by(user_id, screen_name, profile_url, profile_image_url) %>%
  summarize(engagement = (sum(retweet_count) * 2 + sum(favorite_count)) / n()) %>%
  ungroup() %>%
  slice_max(engagement, n = 10, with_ties = FALSE)

top_tweeters_format <- top_tweeters %>% 
  mutate(
    profile_url = stringr::str_glue("https://twitter.com/{screen_name}"),
    screen_name = stringr::str_glue('@{screen_name}'),
    engagement = formattable::color_bar("#a3c1e0", formattable::proportion)(engagement)
  ) %>%
  select(screen_name, engagement)

top_hashtags <- rstats_tweets %>%
  tidyr::separate_rows(hashtags, sep = " ") %>%
  count(hashtags) %>%
  filter(!(hashtags %in% c("rstats", "RStats"))) %>%
  slice_max(n, n = 10, with_ties = FALSE) %>%
  mutate(
    number = formattable::color_bar("plum", formattable::proportion)(n),
    hashtag = stringr::str_glue(
      '#{hashtags}'
    ),
  ) %>%
  select(hashtag, number)

word_banlist <-  c("t.co", "https", "rstats")
top_words <- rstats_tweets %>%
  select(text) %>%
  unnest_tokens(word, text) %>%
  anti_join(stop_words) %>%
  filter(!(word %in% word_banlist)) %>%
  filter(nchar(word) >= 4) %>% 
  count(word, sort = TRUE) %>%
  slice_max(n, n = 10, with_ties = FALSE) %>%     mutate(number = formattable::color_bar("peachpuff", formattable::proportion)(n)) %>%
  select(word, number)
```


Home
====

Row
-----------------------------------------------------------------------

### Tweets Today

```{r}
valueBox(number_of_unique_tweets_today, icon = "fa-comment-alt", color = "plum")
```

### Tweeters Today

```{r}
valueBox(number_of_tweeters_today, icon = "fa-user", color = "peachpuff")
```

### #rstats Likes

```{r}
valueBox(number_of_likes, icon = "fa-heart", color = "palevioletred")
```

### #rstats Tweets

```{r}
valueBox(number_of_unique_tweets, icon = "fa-comments", color = "mediumorchid")
```

Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Tweet volume

```{r}
this_month <- floor_date(today(), "month")

count_timeseries %>%
  e_charts(time) %>%
  e_line(n, name = "# of tweets", smooth = TRUE, legend = FALSE) %>%
  e_x_axis(
    type = "time",
    formatter = htmlwidgets::JS(
      "function(value){
        let date = new Date(value);
        
        label = `${date.getDate()}-${(parseInt(date.getMonth()) + 1)}-${date.getFullYear()}`;
        return label;
      }"
    )
  ) %>%
  e_axis_labels(y = "Tweets") %>%
  e_theme("westeros") %>%
  e_tooltip(trigger = "axis", formatter = htmlwidgets::JS("
    function(params) {
      let date = new Date(params[0].value[0])
      let options = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric'}
      let title = `${date.toLocaleDateString('en-US', options=options)}`
      let num = `${params[0].value[1]} tweets`
      return(`${title}
${num}`); }")) %>% e_datazoom(type = "slider") %>% e_zoom( dataZoomIndex = 0, start = 70, end = 100 ) %>% e_zoom( dataZoomIndex = 0, startValue = today() - 7, endValue = today(), btn = "weekBtn" ) %>% e_zoom( dataZoomIndex = 0, startValue = this_month, endValue = today(), btn = "monthBtn" ) %>% e_button( id = "weekBtn", position = "top", class = "btn btn-primary btn-sm", "This Week" ) %>% e_button( id = "monthBtn", position = "top", class = "btn btn-primary btn-sm", "This Month" ) ``` ### Tweets by Hour of Day ```{r} by_hour %>% e_charts(hour) %>% e_step(count, name = "Tweets", step = "middle", legend = FALSE) %>% e_x_axis( min = 0, max = 23, ) %>% e_axis_labels(x = "Time of Day (UTC)", y = "Tweets") %>% e_theme("westeros") %>% e_tooltip(trigger = "axis", formatter = htmlwidgets::JS(" function(params) { let title = `${params[0].value[0]}h` let num = `${params[0].value[1]} tweets` return(`${title}
${num}`); }")) ``` Row ----------------------------------------------------------------------- ### 💗 Most Liked Tweet Today {.tweet-box} ```{r} most_liked_url <- tweets_today %>% slice_max(favorite_count) get_tweet_embed(most_liked_url$screen_name, most_liked_url$status_id) ``` ### ✨ Most Retweeted Tweet Today {.tweet-box} ```{r} most_retweeted <- tweets_today %>% slice_max(retweet_count) get_tweet_embed(most_retweeted$screen_name, most_retweeted$status_id) ``` ### 🎉 Most Recent {.tweet-box} ```{r} most_recent <- tweets_today %>% slice_max(created_at, with_ties=FALSE) get_tweet_embed(most_recent$screen_name, most_recent$status_id) ``` Rankings ========= Row ----------------------------------------------------------------------- ### Top Tweeters ```{r} top_tweeters_format %>% knitr::kable( format = "html", escape = FALSE, align = "cll", col.names = c("User", "Engagement/Tweet "), table.attr = 'class = "table"' ) ``` Where Engagement is `RT * 2 + Favourite` ### Network of top tweeters Relationships in the graph describe replies and quote retweets from the top tweeters ```{r} edgelist <- network_data(rstats_tweets %>% unflatten(), "reply,quote") nodelist <- attr(edgelist, "idsn") %>% bind_cols() top_edges <- edgelist %>% filter((from %in% top_tweeters$user_id) | (to %in% top_tweeters$user_id)) top_nodes <- nodelist %>% filter((id %in% top_edges$from) | (id %in% top_edges$to)) %>% mutate(is_top = ifelse((id %in% top_tweeters$user_id), "yes", "no"), size = 10) e_charts() %>% e_graph() %>% e_graph_nodes(top_nodes, id, sn, size, category = is_top, legend = FALSE) %>% e_graph_edges(top_edges, from, to) %>% e_tooltip() ``` Row ----------------------------------------------------------------------- ### Top Hashtags ```{r} top_hashtags %>% knitr::kable( format = "html", escape = FALSE, align = "cll", col.names = c("Hashtag", "Count"), table.attr = 'class = "table"' ) ``` Excluding `#rstats` and similar variations ### Top Words ```{r} top_words %>% knitr::kable( format = "html", escape = FALSE, align = "cll", col.names = c("Word", "Count"), table.attr = 'class = "table"' ) ``` Data ============== ### Tweets in the current week {.datatable-container} ```{r} tweets_week %>% select( status_url, created_at, screen_name, text, retweet_count, favorite_count, mentions_screen_name ) %>% mutate( status_url = stringr::str_glue("On Twitter") ) %>% datatable( ., extensions = "Buttons", rownames = FALSE, escape = FALSE, colnames = c("Timestamp", "User", "Tweet", "RT", "Fav", "Mentioned"), filter = 'top', options = list( columnDefs = list(list( targets = 0, searchable = FALSE )), lengthMenu = c(5, 10, 25, 50, 100), pageLength = 10, scrollY = 600, scroller = TRUE, dom = '<"d-flex justify-content-between"lBf>rtip', buttons = list('copy', list( extend = 'collection', buttons = c('csv', 'excel'), text = 'Download' )) ) ) ```